cmake_minimum_required(VERSION 2.8)

project(power)

# 将config.h.in的内容生成为config.h
configure_file(
    "${PROJECT_SOURCE_DIR}/config.h.in"
    "${PROJECT_BINARY_DIR}/config.h"
)

# 添加选项
option(USE_MYMATH "use provided math implementation" ON)

if (USE_MYMATH)
    include_directories("${PROJECT_SOURCE_DIR}/math")
    add_subdirectory(math)
    # 设置变量
    set(POWER_LIB ${POWER_LIB} powerlib)
endif (USE_MYMATH)

aux_source_directory(. MAIN)

add_executable(power ${MAIN})
target_link_libraries(power ${POWER_LIB})

# gcc -g
set(CMAKE_BUILD_TYPE "Debug")
set(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -Wall -g -ggdb")
set(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O3 -Wall")

# 检查系统是否支持 pow 函数
include (${CMAKE_ROOT}/Modules/CheckFunctionExists.cmake)
check_function_exists (pow HAVE_POW)